/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.marc.juliator.gui.peptideprotein;

import com.compomics.util.experiment.identification.SequenceFactory;
import eu.marc.juliator.gui.io.InputFile;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import javax.swing.table.DefaultTableModel;

/**
 * table model for a peptide input
 *
 * @author Marc
 */
public class InputTableModel extends DefaultTableModel {

    /**
     * the input file
     */
    private InputFile inputFile = null;

    /**
     * Constructor
     */
    public InputTableModel(InputFile inputFile) {
        this.inputFile = inputFile;
    }

    @Override
    public int getRowCount() {
        if (inputFile == null) {
            return 0;
        }
        return inputFile.getNLines()-1;
    }

    @Override
    public int getColumnCount() {
        if (inputFile == null) {
            return 0;
        }
        return inputFile.getNColumns();
    }

    @Override
    public String getColumnName(int column) {
        try {
            return inputFile.getValueAt(0, column);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    @Override
    public Object getValueAt(int row, int column) {
        try {
            return inputFile.getValueAt(row+1, column);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    @Override
    public Class getColumnClass(int columnIndex) {
        for (int i = 0; i < getRowCount(); i++) {
            if (getValueAt(i, columnIndex) != null) {
                return getValueAt(i, columnIndex).getClass();
            }
        }
        return String.class;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    }
}
